package pe.edu.upc.dsd.epica.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import pe.edu.upc.dsd.epica.model.Establecimiento;
import pe.edu.upc.dsd.epica.util.Session;

public class IndexServlet  extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
    
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		doAction(req, resp);
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		doAction(req, resp);
		
	}
	
	private void doAction(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		Establecimiento establecimiento = Session.ObtenerValor(req.getSession());
		
		if(establecimiento == null)
		{
			req.getRequestDispatcher("CerrarSesion").forward(req, resp);
			return;
		}
		
		req.setAttribute("establecimiento", establecimiento);
		req.getRequestDispatcher("index.jsp").forward(req,resp);	
	}
	
}

